import { defineStore } from 'pinia'
import { ref } from 'vue'
import { searchUserInfo } from '@/api/user'
import { user } from '@/model/userModel'

export default defineStore('user', () => {
  const userInfo = ref<user>()
  const nickName = ref<string>()
  const getUserInfo = async () => {
    const result = await searchUserInfo()
    if (result.status == 200) {
      userInfo.value = result.data[0]
      nickName.value = result.data[0].user_name
      localStorage.setItem('userId', result.data[0].user_id)
    }
  }

  return {
    userInfo,
    nickName,
    getUserInfo
  }
})
